<?php
/**
 * Created by PhpStorm.
 * User: crystal
 * Date: 2017/9/6
 * Time: 17:07
 */
namespace Zoo;

use Animal\Animal;

class Zoo
{
    private $animalCollection;

    public function addAnimal(Animal $animal)
    {
        $this->animalCollection[] = $animal;
    }

    public function watch()
    {
        foreach ($this->animalCollection as $animal) {
            if ($animal instanceof Animal) {
                $animal->eat();
                $animal->play();
                $animal->sleep();
            }
            echo '<br/><br/>';
        }
    }

    public function kill()
    {
        $count = count($this->animalCollection);
        $index = mt_rand(0, $count - 1);
        $animal = $this->animalCollection[$index];
        echo $animal->type . ' ' . $animal->name . ' ' . 'will be killed' . '<br/>';
        $animal->toBeKill();
    }
}